package com.bite.order.service;


import com.bite.order.mapper.OrderMapper;
import com.bite.order.model.OrderInfo;
import com.bite.product.api.ProductApi;
import com.bite.product.model.ProductInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: Yun
 * @Date: 2025/5/31
 */
@Service
public class OrderService {
    @Resource
    private OrderMapper orderMapper;

    @Resource
    private ProductApi productApi;
    @Resource
    private RestTemplate restTemplate;

    public OrderInfo selectOrderById(Integer orderId) {
        OrderInfo orderInfo = orderMapper.selectOrderById(orderId);
//        String url = "http://product-service/product/" + orderInfo.getProductId();
//        ProductInfo productInfo = restTemplate.getForObject(url, ProductInfo.class);
        ProductInfo productInfo = productApi.getProductById(orderInfo.getProductId());
        orderInfo.setProductInfo(productInfo);
        return orderInfo;
    }


}
